//
//  BRToolsView.m
//  BrezzeSaaS
//
//  Created by IOS on 2021/9/23.
//  Copyright © 2021 Brezze GWG. All rights reserved.
//

#import "BRToolsView.h"

@implementation BRToolsView


+ (QMUIButton *)br_fillBtn:(NSString *)title font:(UIFont *)font {
    
    return [BRToolsView br_fillBtn:title font:font titleColor:UIColorWhite bgImg:UIImage.qd_homeScanBtnImage];
}
+ (QMUIButton *)br_fillBtn:(NSString *)title font:(UIFont *)font titleColor:(UIColor *)titleColor {
    return [BRToolsView br_fillBtn:title font:font titleColor:titleColor bgImg:UIImage.qd_homeScanBtnImage];
}


+ (QMUIButton *)br_fillBtn:(NSString *)title font:(UIFont *)font titleColor:(UIColor *)titleColor bgImg:(UIImage *)bgImg {
    QMUIButton *supBtn = [[QMUIButton alloc] init];
    [supBtn setTitleColor:titleColor forState:UIControlStateNormal];
    [supBtn setBackgroundImage:bgImg forState:UIControlStateNormal];
    supBtn.layer.masksToBounds = YES;
    supBtn.titleLabel.font = font;
    [supBtn setTitle:title forState:UIControlStateNormal];
    return supBtn;
}

+ (void)br_addShadow:(UIView *)view radius:(CGFloat)radius shadowColor:(UIColor *)color {
    // Shadow Code
    view.layer.shadowColor = color.CGColor;
    view.layer.shadowOffset = CGSizeMake(0,4);
    view.layer.shadowRadius = radius;
    view.layer.shadowOpacity = 1;
}

+ (UIView *)getLineView {
    
    return [[self class] getLineView:UIColorMakeWithHex(@"#D2D8E2")];
}

+ (UIView *)getLineView:(UIColor *)color {
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = color;
    return line;
}

+ (UIView *)br_contentView {
    return [[self class] br_contentView:UIColor.whiteColor cornerRadius:13];
}

+ (UIView *)br_contentViewRadius:(CGFloat)r {
    return [[self class] br_contentView:UIColor.whiteColor cornerRadius:r];
}

+ (UIView *)br_contentView:(UIColor *)color cornerRadius:(CGFloat)r  {
    UIView *contentView = [[UIView alloc] init];
    contentView.backgroundColor = color;
    if (r > 0) {
        contentView.layer.cornerRadius = r;
        contentView.layer.masksToBounds = YES;
    }
    return contentView;
}

+ (UIImageView *)br_imgViewCornerR:(CGFloat)r {
    return [[self class] br_imgView:@"" cornerR:r];
}

+ (UIImageView *)br_imgView:(NSString *)defaultImg cornerR:(CGFloat)r {
    UIImageView *brandImg = [[UIImageView alloc] init];
    if (defaultImg.length != 0) {
        brandImg.image = UIImageMake(defaultImg);
    }
    if (r != 0) {
        brandImg.layer.cornerRadius = r;
        brandImg.layer.masksToBounds = YES;
    }
    return brandImg;
}

+ (QMUILabel *)br_label:(NSString *)text textColor:(UIColor *)textColor font:(UIFont *)font textAlignment:(NSTextAlignment)alignment  {
    
    QMUILabel *label = [[QMUILabel alloc] init];
    label.text = text;
    label.textColor = textColor;
    label.font = font;
    label.textAlignment = alignment;
    return label;
}


+ (QMUILabel *)br_label:(NSString *)text textColor:(UIColor *)textColor font:(UIFont *)font {
    return [BRToolsView br_label:text textColor:textColor font:font textAlignment:NSTextAlignmentLeft];
}
+ (QMUIButton *)br_btn:(NSString *)text textColor:(UIColor *)textColor font:(UIFont *)font {
    QMUIButton *btn = [[QMUIButton alloc] init];
    [btn setTitleColor:textColor forState:UIControlStateNormal];
    btn.titleLabel.font = font;
    [btn setTitle:text forState:UIControlStateNormal];
  
    return btn;
}

+ (QMUIButton *)br_btnDefault:(NSString *)text {
    
    return [[self class] br_btnDefault:text bgColor:kColorBtnBG radius:26];
}

+ (QMUIButton *)br_btnDefault:(NSString *)text bgColor:(UIColor *)bgC radius:(CGFloat)r {
    
    QMUIButton *btn = [BRToolsView br_btn:text textColor:UIColor.whiteColor font:[UIFont br_fontB:17]];
    [btn setBackgroundColor:bgC];
    if (r > 0) {
        btn.layer.cornerRadius = r;
        btn.layer.masksToBounds = YES;
    }
    
    return btn;
}

+ (QMUIButton *)br_btnBGImg:(NSString *)text {
//    UIImage *bubble = UIImageMake(@"bgBtn");
//    UIImage *bubbleNew = [bubble resizableImageWithCapInsets:UIEdgeInsetsMake(0, 40, 0, 40) resizingMode:UIImageResizingModeStretch];
    
    QMUIButton *btn = [[QMUIButton alloc] init];
    [btn setTitle:text forState:UIControlStateNormal];
    [btn setTitleColor:UIColorWhite forState:UIControlStateNormal];
//    [btn setBackgroundImage:bubbleNew forState:UIControlStateNormal];
    [btn setBackgroundColor:kColorMain];
    btn.titleLabel.font = [UIFont fontB:17];
    btn.layer.cornerRadius = 26;
    btn.layer.masksToBounds = YES;
  
    return btn;
}



+ (QMUIButton *)br_btnborder:(NSString *)text {

    
    return [BRToolsView br_btnborder:text radius:14 font:[UIFont br_fontS:12]];
}

+ (QMUIButton *)br_btnborder:(NSString *)text radius:(CGFloat)radius {
    
    return [BRToolsView br_btnborder:text radius:radius font:[UIFont br_fontS:12]];
    
}
+ (QMUIButton *)br_btnborder:(NSString *)text radius:(CGFloat)radius font:(UIFont *)font {

    QMUIButton *bBtn = [BRToolsView br_btn:text textColor:kColorTitle font:font];
    bBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 16, 0, 16);
    bBtn.layer.cornerRadius = radius;
    bBtn.layer.masksToBounds = YES;
    bBtn.layer.borderColor = kColorMain.CGColor;
    bBtn.layer.borderWidth = 0.5;
    
    return bBtn;
    
}


+ (CAShapeLayer *)br_separatorDashLayerWithLineLength:(NSInteger)lineLength
                                            lineSpacing:(NSInteger)lineSpacing
                                              lineWidth:(CGFloat)lineWidth
                                              lineColor:(CGColorRef)lineColor
                                         isHorizontal:(BOOL)isHorizontal frame:(CGRect)frame {
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.fillColor = UIColorClear.CGColor;
    layer.strokeColor = lineColor;
    layer.frame = frame;
    layer.lineWidth = lineWidth;
    layer.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInteger:lineLength], [NSNumber numberWithInteger:lineSpacing], nil];
    layer.masksToBounds = YES;
    
    CGMutablePathRef path = CGPathCreateMutable();
    if (isHorizontal) {
        CGPathMoveToPoint(path, NULL, 0, lineWidth / 2);
        CGPathAddLineToPoint(path, NULL, SCREEN_WIDTH, lineWidth / 2);
    } else {
        CGPathMoveToPoint(path, NULL, lineWidth / 2, 0);
        CGPathAddLineToPoint(path, NULL, lineWidth / 2, SCREEN_HEIGHT);
    }
    layer.path = path;
    CGPathRelease(path);
    
    return layer;
}

+ (CAShapeLayer *)br_corners:(CGFloat)cornerSize corners:(UIRectCorner)corners by:(UIView *)view  {
    
    [view layoutIfNeeded];
    // 设置顶部圆角
    // 绘制圆角 需设置的圆角 使用"|"来组合
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(cornerSize, cornerSize)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];

    // 设置大小
    maskLayer.frame = view.bounds;

    // 设置图形样子
    maskLayer.path = maskPath.CGPath;
    view.layer.mask = maskLayer;
    return maskLayer;
}

+ (void)br_setImgUrl:(NSString *)urlAddress to:(UIImageView *)imgV {
    [BRToolsView br_setImgUrl:urlAddress to:imgV defaultImg:@"avatar_default"];
}
+ (void)br_setImgUrl:(NSString *)urlAddress to:(UIImageView *)imgV defaultImg:(NSString *)defaultImg {
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",[BRUserManager share].filesSever,urlAddress];
    [imgV sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:UIImageMake(defaultImg)];
}


+ (void)br_default:(NSString *)title text:(NSString *)text succ:(BRVoidBlock)succ cancel:(BRVoidBlock)cancel inView:(UIView * _Nullable)view {
    
    BRCustiomAlertView *alertV = [[BRCustiomAlertView alloc] initWithTitle:title subTitle:text cancelStr:Localized(@"public_cancel") succStr:Localized(@"profile_confirm") cancelAction:cancel successAction:succ showBC:YES];
    if (!view) {
//        [alertV br_showAdd];
    }else {
        [view addSubview:alertV];
    }
}

+ (void)br_defaultText:(NSString *)text succ:(BRVoidBlock)succ cancel:(BRVoidBlock)cancel inView:(UIView * _Nullable)view {
    
    [BRToolsView br_default:@"" text:text succ:succ cancel:cancel inView:view];
}

+ (void)br_Lock:(BOOL)lock succ:(BRVoidBlock)succ cancel:(BRVoidBlock)cancel inView:(UIView * _Nullable)view {
    NSString *text = lock ? Localized(@"station_confirmLock") : Localized(@"station_confirmUnlock");
    [BRToolsView br_defaultText:text succ:succ cancel:cancel inView:view];
}
+ (void)br_ejectAllSucc:(BRVoidBlock)succ cancel:(BRVoidBlock)cancel inView:(UIView * _Nullable)view {
    
    [BRToolsView br_defaultText:Localized(@"station_confirmEject") succ:succ cancel:cancel inView:view];
}

+ (void)br_freeze:(BOOL)state succ:(BRVoidBlock)succ cancel:(BRVoidBlock)cancel inView:(UIView * _Nullable)view {
    NSString *title = state ? Localized(@"user_freeze") : Localized(@"user_unfreeze");
    NSString *text = state ? Localized(@"user_frezzeUserText") : Localized(@"user_unfrezzeUserText");
    [BRToolsView br_default:title text:text succ:succ cancel:cancel inView:view];
}

+ (void)br_refund:(BRVoidBlock)succ cancel:(BRVoidBlock)cancel inView:(UIView * _Nullable)view {
    
    [BRToolsView br_default:Localized(@"user_depositRefund") text:Localized(@"user_confirmRefund") succ:succ cancel:cancel inView:view];
}

+ (void)br_suspend:(BOOL)state succ:(BRVoidBlock)succ cancel:(BRVoidBlock)cancel inView:(UIView * _Nullable)view {
    
    NSString *title = state ? Localized(@"franchise_confirmSuspend") : @"";
    NSString *text = state ? Localized(@"franchise_suspendText") : Localized(@"franchise_confirmResume");
    [BRToolsView br_default:title text:text succ:succ cancel:cancel inView:view];
}

+ (void)br_suspendShop:(BOOL)state succ:(BRVoidBlock)succ cancel:(BRVoidBlock)cancel inView:(UIView * _Nullable)view {
    
    NSString *title = state ? Localized(@"shop_confirmTerminate") : Localized(@"shop_reactivate");
    NSString *text = state ? Localized(@"shop_confirmTerminateText") : Localized(@"shop_reactivateText");
    [BRToolsView br_default:title text:text succ:succ cancel:cancel inView:view];
}

+ (void)br_refresh:(BRVoidBlock)succ cancel:(BRVoidBlock)cancel inView:(UIView * _Nullable)view {
    
    [BRToolsView br_default:Localized(@"station_refreshBC") text:Localized(@"station_refreshBCText") succ:succ cancel:cancel inView:view];
}

+ (void)br_ejectSucc:(BRVoidBlock)succ cancel:(BRVoidBlock)cancel inView:(UIView * _Nullable)view {
    
    BRCustiomAlertView *alertV = [[BRCustiomAlertView alloc] initWithTitle:Localized(@"station_ejectTitle") subTitle:Localized(@"station_ejectText") cancelStr:Localized(@"public_cancel") succStr:Localized(@"station_eject") cancelAction:cancel successAction:succ showBC:YES];
    if (!view) {
//        [alertV br_showAdd];
    }else {
        [view addSubview:alertV];
    }
}

+ (void)br_recoverSucc:(BRVoidBlock)succ cancel:(BRVoidBlock)cancel inView:(UIView * _Nullable)view {
    
    [BRToolsView br_default:Localized(@"pb_recoverTile") text:Localized(@"pb_recoverText") succ:succ cancel:cancel inView:view];
}

@end
